<template>
  <el-dialog
    :title="!dataForm.rentOutRoomId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="出租房名称" prop="rent OutName">
      <el-input v-model="dataForm.rent OutName" placeholder="出租房名称"></el-input>
    </el-form-item>
    <el-form-item label="出租房标题" prop="rentOutTitle">
      <el-input v-model="dataForm.rentOutTitle" placeholder="出租房标题"></el-input>
    </el-form-item>
    <el-form-item label="总价" prop="rentOutPrice">
      <el-input v-model="dataForm.rentOutPrice" placeholder="总价"></el-input>
    </el-form-item>
    <el-form-item label="单价" prop="rentOutOnePrice">
      <el-input v-model="dataForm.rentOutOnePrice" placeholder="单价"></el-input>
    </el-form-item>
    <el-form-item label="面积" prop="rentOutArea">
      <el-input v-model="dataForm.rentOutArea" placeholder="面积"></el-input>
    </el-form-item>
    <el-form-item label="默认图片" prop="rentOutDefaultImage">
      <el-input v-model="dataForm.rentOutDefaultImage" placeholder="默认图片"></el-input>
    </el-form-item>
    <el-form-item label="楼层" prop="rentOutFloor">
      <el-input v-model="dataForm.rentOutFloor" placeholder="楼层"></el-input>
    </el-form-item>
    <el-form-item label="服务介绍" prop="rentOutIntroduce">
      <el-input v-model="dataForm.rentOutIntroduce" placeholder="服务介绍"></el-input>
    </el-form-item>
    <el-form-item label="核心买点" prop="rentOutSoreSell">
      <el-input v-model="dataForm.rentOutSoreSell" placeholder="核心买点"></el-input>
    </el-form-item>
    <el-form-item label="业主心态" prop="rentOutOwner">
      <el-input v-model="dataForm.rentOutOwner" placeholder="业主心态"></el-input>
    </el-form-item>
    <el-form-item label="1 商铺 2 写字楼 3 小区" prop="rentOutTypeStatus">
      <el-input v-model="dataForm.rentOutTypeStatus" placeholder="1 商铺 2 写字楼 3 小区"></el-input>
    </el-form-item>
    <el-form-item label="经纪人id" prop="brokerId">
      <el-input v-model="dataForm.brokerId" placeholder="经纪人id"></el-input>
    </el-form-item>
    <el-form-item label="属性组id" prop="propertyId">
      <el-input v-model="dataForm.propertyId" placeholder="属性组id"></el-input>
    </el-form-item>
    <el-form-item label="楼盘名称" prop="rentOutHousesName">
      <el-input v-model="dataForm.rentOutHousesName" placeholder="楼盘名称"></el-input>
    </el-form-item>
    <el-form-item label="详细地址" prop="rentOutRoomAddress">
      <el-input v-model="dataForm.rentOutRoomAddress" placeholder="详细地址"></el-input>
    </el-form-item>
    <el-form-item label="排序" prop="sort">
      <el-input v-model="dataForm.sort" placeholder="排序"></el-input>
    </el-form-item>
    <el-form-item label="0 未提交 1 已提交 2 待提交" prop="status">
      <el-input v-model="dataForm.status" placeholder="0 未提交 1 已提交 2 待提交"></el-input>
    </el-form-item>
    <el-form-item label="地区id" prop="cityId">
      <el-input v-model="dataForm.cityId" placeholder="地区id"></el-input>
    </el-form-item>
    <el-form-item label="起租时间" prop="startTime">
      <el-input v-model="dataForm.startTime" placeholder="起租时间"></el-input>
    </el-form-item>
    <el-form-item label="结束时间" prop="endTime">
      <el-input v-model="dataForm.endTime" placeholder="结束时间"></el-input>
    </el-form-item>
    <el-form-item label="是否同步 es(1 或 0 )" prop="isEs">
      <el-input v-model="dataForm.isEs" placeholder="是否同步 es(1 或 0 )"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="修改时间"></el-input>
    </el-form-item>
    <el-form-item label="是否删除" prop="delStatus">
      <el-input v-model="dataForm.delStatus" placeholder="是否删除"></el-input>
    </el-form-item>
    <el-form-item label="房源类型id" prop="typeId">
      <el-input v-model="dataForm.typeId" placeholder="房源类型id"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          rentOutRoomId: 0,
          rent OutName: '',
          rentOutTitle: '',
          rentOutPrice: '',
          rentOutOnePrice: '',
          rentOutArea: '',
          rentOutDefaultImage: '',
          rentOutFloor: '',
          rentOutIntroduce: '',
          rentOutSoreSell: '',
          rentOutOwner: '',
          rentOutTypeStatus: '',
          brokerId: '',
          propertyId: '',
          rentOutHousesName: '',
          rentOutRoomAddress: '',
          sort: '',
          status: '',
          cityId: '',
          startTime: '',
          endTime: '',
          isEs: '',
          createTime: '',
          updateTime: '',
          delStatus: '',
          typeId: ''
        },
        dataRule: {
          rent OutName: [
            { required: true, message: '出租房名称不能为空', trigger: 'blur' }
          ],
          rentOutTitle: [
            { required: true, message: '出租房标题不能为空', trigger: 'blur' }
          ],
          rentOutPrice: [
            { required: true, message: '总价不能为空', trigger: 'blur' }
          ],
          rentOutOnePrice: [
            { required: true, message: '单价不能为空', trigger: 'blur' }
          ],
          rentOutArea: [
            { required: true, message: '面积不能为空', trigger: 'blur' }
          ],
          rentOutDefaultImage: [
            { required: true, message: '默认图片不能为空', trigger: 'blur' }
          ],
          rentOutFloor: [
            { required: true, message: '楼层不能为空', trigger: 'blur' }
          ],
          rentOutIntroduce: [
            { required: true, message: '服务介绍不能为空', trigger: 'blur' }
          ],
          rentOutSoreSell: [
            { required: true, message: '核心买点不能为空', trigger: 'blur' }
          ],
          rentOutOwner: [
            { required: true, message: '业主心态不能为空', trigger: 'blur' }
          ],
          rentOutTypeStatus: [
            { required: true, message: '1 商铺 2 写字楼 3 小区不能为空', trigger: 'blur' }
          ],
          brokerId: [
            { required: true, message: '经纪人id不能为空', trigger: 'blur' }
          ],
          propertyId: [
            { required: true, message: '属性组id不能为空', trigger: 'blur' }
          ],
          rentOutHousesName: [
            { required: true, message: '楼盘名称不能为空', trigger: 'blur' }
          ],
          rentOutRoomAddress: [
            { required: true, message: '详细地址不能为空', trigger: 'blur' }
          ],
          sort: [
            { required: true, message: '排序不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '0 未提交 1 已提交 2 待提交不能为空', trigger: 'blur' }
          ],
          cityId: [
            { required: true, message: '地区id不能为空', trigger: 'blur' }
          ],
          startTime: [
            { required: true, message: '起租时间不能为空', trigger: 'blur' }
          ],
          endTime: [
            { required: true, message: '结束时间不能为空', trigger: 'blur' }
          ],
          isEs: [
            { required: true, message: '是否同步 es(1 或 0 )不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          delStatus: [
            { required: true, message: '是否删除不能为空', trigger: 'blur' }
          ],
          typeId: [
            { required: true, message: '房源类型id不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.rentOutRoomId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.rentOutRoomId) {
            this.$http({
              url: this.$http.adornUrl(`/house/houserentout/info/${this.dataForm.rentOutRoomId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.rent OutName = data.houseRentOut.rent OutName
                this.dataForm.rentOutTitle = data.houseRentOut.rentOutTitle
                this.dataForm.rentOutPrice = data.houseRentOut.rentOutPrice
                this.dataForm.rentOutOnePrice = data.houseRentOut.rentOutOnePrice
                this.dataForm.rentOutArea = data.houseRentOut.rentOutArea
                this.dataForm.rentOutDefaultImage = data.houseRentOut.rentOutDefaultImage
                this.dataForm.rentOutFloor = data.houseRentOut.rentOutFloor
                this.dataForm.rentOutIntroduce = data.houseRentOut.rentOutIntroduce
                this.dataForm.rentOutSoreSell = data.houseRentOut.rentOutSoreSell
                this.dataForm.rentOutOwner = data.houseRentOut.rentOutOwner
                this.dataForm.rentOutTypeStatus = data.houseRentOut.rentOutTypeStatus
                this.dataForm.brokerId = data.houseRentOut.brokerId
                this.dataForm.propertyId = data.houseRentOut.propertyId
                this.dataForm.rentOutHousesName = data.houseRentOut.rentOutHousesName
                this.dataForm.rentOutRoomAddress = data.houseRentOut.rentOutRoomAddress
                this.dataForm.sort = data.houseRentOut.sort
                this.dataForm.status = data.houseRentOut.status
                this.dataForm.cityId = data.houseRentOut.cityId
                this.dataForm.startTime = data.houseRentOut.startTime
                this.dataForm.endTime = data.houseRentOut.endTime
                this.dataForm.isEs = data.houseRentOut.isEs
                this.dataForm.createTime = data.houseRentOut.createTime
                this.dataForm.updateTime = data.houseRentOut.updateTime
                this.dataForm.delStatus = data.houseRentOut.delStatus
                this.dataForm.typeId = data.houseRentOut.typeId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/house/houserentout/${!this.dataForm.rentOutRoomId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'rentOutRoomId': this.dataForm.rentOutRoomId || undefined,
                'rent OutName': this.dataForm.rent OutName,
                'rentOutTitle': this.dataForm.rentOutTitle,
                'rentOutPrice': this.dataForm.rentOutPrice,
                'rentOutOnePrice': this.dataForm.rentOutOnePrice,
                'rentOutArea': this.dataForm.rentOutArea,
                'rentOutDefaultImage': this.dataForm.rentOutDefaultImage,
                'rentOutFloor': this.dataForm.rentOutFloor,
                'rentOutIntroduce': this.dataForm.rentOutIntroduce,
                'rentOutSoreSell': this.dataForm.rentOutSoreSell,
                'rentOutOwner': this.dataForm.rentOutOwner,
                'rentOutTypeStatus': this.dataForm.rentOutTypeStatus,
                'brokerId': this.dataForm.brokerId,
                'propertyId': this.dataForm.propertyId,
                'rentOutHousesName': this.dataForm.rentOutHousesName,
                'rentOutRoomAddress': this.dataForm.rentOutRoomAddress,
                'sort': this.dataForm.sort,
                'status': this.dataForm.status,
                'cityId': this.dataForm.cityId,
                'startTime': this.dataForm.startTime,
                'endTime': this.dataForm.endTime,
                'isEs': this.dataForm.isEs,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'delStatus': this.dataForm.delStatus,
                'typeId': this.dataForm.typeId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
